from app import app, db
from models import User
from werkzeug.security import generate_password_hash

def fix_passwords():
    with app.app_context():
        # 获取所有用户
        users = User.query.all()
        
        for user in users:
            # 检查密码是否已经是哈希格式
            if not user.password.startswith('pbkdf2:sha256:'):
                # 将明文密码转换为哈希密码
                user.password = generate_password_hash(user.password)
                print(f"Updated password for user: {user.username}")
        
        # 提交更改
        db.session.commit()
        print("Password update completed!")

if __name__ == '__main__':
    fix_passwords() 